function mySetInteval(fn, delay) {
  let timer = null
  function _tmpFn() {
    timer = setTimeout(() => {
      fn()
      _tmpFn()
    }, delay)
  }
  function clearMyInterval() {
    clearTimeout(timer)
  }

  _tmpFn()
  return {
    clear: clearMyInterval
  }
}

// let timer = mySetInteval(() => {
//   console.log('123');
// }, 1000)
// setTimeout(() => {
//   timer.clear()
// }, 4100)

function mySetTimeout(fn, delay) {
  let timer = setInterval(() => {
    fn()
    clearInterval(timer)
  }, delay)
}
mySetTimeout(()=>{
console.log('abcd');
},1000)